package com.coding365.service.user.service.impl;

import com.coding365.service.user.dao.LagouTokenMapper;
import com.coding365.service.user.entity.LagouToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class JdbcUserDetailsService implements UserDetailsService {

    @Autowired
    private LagouTokenMapper lagouTokenMapper;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        LagouToken lagouToken = lagouTokenMapper.selectLagouTokenWithEmail(s);
        if (lagouToken != null){
            return new User(lagouToken.getEmail(),lagouToken.getPassword(),new ArrayList<>());
        }
        return null;
    }
}
